<#assign  title="新增地址" />
<#include '/common/header.html'>
<#assign regionSelect = "com.enation.app.shop.front.tag.goods.other.regions.RegionSelectDirective"?new()>
<link rel="stylesheet" type="text/css" href="themes/wap/css/easyui.css" />
<script src="themes/wap/js/jquery.easyui.min.js" ></script>
<link rel="stylesheet" type="text/css" href="themes/wap/css/member.css" />
<script type="text/javascript" src="${ctx}${themes_path}/js/jquery.form.min.js"></script>
<#assign memberLoginCheckTag = newTag("memberLoginCheckTag") />
<#assign memberInfo = memberLoginCheckTag() />
<div class="header-tools">
	<div class="go-back">
		<a href="javascript:" onclick="window.history.go(-1);"></a>
	</div>
	<div class="common-title">
		新增地址
	</div>
	<div class="go-search">
	</div>
</div>
<div class="add_adress">
<form id="member_addr"  class="validate"   action="" method="post">
	<div class="newadress">
		<ul>
			<li>
				
					<input type="text" name="name" class="membername same" placeholder="收货人姓名" value=""></input>
					<span class="a_border"></span>
			</li>
			<li>
				
					<input type="text" name="mobile" class="membermobile same" value="" placeholder="电话" maxlength="11"></input>
					<span class="a_border"></span>
			</li>
			<li class="site">
					<@regionSelect />
			</li>
			<li>
					<input type="text" name="addr" class="adrintro same" value="" placeholder="详细地址"></input>
					<span class="a_border"></span>
			</li>
			<li>
				
					<input type="text" name="zip" class="memberezip same" value="" placeholder="邮政编码" maxlength="6"></input>
					<span class="a_border"></span>
			</li>
		</ul>
	</div>	
	<div class="a_outside">
			<h2>是否默认：</h2>
			<div class="is_default">
				<label class="selected"><input type="radio"   value="0" name="def_addr"  class="address_default" checked="checked" style="display:none"><p>否</p></label> 
				<label><input type="radio"   value="1"  name="def_addr" class="address_default" style="display:none"><p>是</p></label>
			</div>
		</div>			
	<div class="save_address address_button" >
		保存地址
	</div>
	<div class="address_back address_button">
		<a href="addresslist.html?back=${back}">取消</a>
	</div>
</form>
</div>

<script>

//订单提交页-验证邮政编码  
function is_postcode(postcode) {  
    if ( postcode == "") {  
        return false;  
    } else {  
        if (! /^[0-9][0-9]{5}$/.test(postcode)) {  
            return false;  
        }  
    }  
    return true;  
}  
  


$(function(){
	//根据参数名称获得参数值（地址函数）
	function getUrlParam(strname) {  
	    var hrefstr, pos, parastr, para, tempstr;  
	    hrefstr = window.location.href;  
	    pos = hrefstr.indexOf("?");  
	    parastr = hrefstr.substring(pos + 1);  
	    para = parastr.split("&");  
	    tempstr = "";  
	    for (i = 0; i < para.length; i++) {  
	        tempstr = para[i];  
	        pos = tempstr.indexOf("=");  
	        if (tempstr.substring(0, pos) == strname) {  
	            return tempstr.substring(pos + 1).replace("#", "");  
	        }  
	    }  
	    return null;  
	} 
	$(".save_address").click(function(){
		 //判断邮编
		var postcode=$(".memberezip").val();  
        if(is_postcode(postcode)){  
        }else{  
            alert("邮编格式不正确");  
            return false;  
        }   
		// 判断三级地址是否完全
		if($("#region_id").val()==0){
			 alert("地址错误");  
	            return false;  
		}
		
		//判断收货人是否为空
		if($(".membername").val()==""){
			 alert("收货人不能为空");  
	            return false;  
		}
		
		
		//判断收货电话是否为空
		if($(".membermobile").val()==""){
			 alert("联系电话不能为空");  
	            return false;  
		}
		
		//判断收货地址是否为空
		if($(".adrintro").val()==""){
			 alert("详细地址不能为空");  
	            return false;  
		}
		
		
	 	show.show_cover();       //增加遮罩。来阻止在提交ajax时进行其他操作。
		$("#member_addr").ajaxSubmit({
			url :"${ctx}/api/shop/member-address/add.do",
			dataType : 'json',
			success : function(data) {	
				alert(data.message)
				if(data.result==1){
					//调用地址函数,如果地址参数back是1，那么说明是在会员中心下的地址列表中进行修改，如果是2，说明是在结算页调转，根据back参数觉得跳转回那里。
					var goReturn=  getUrlParam("back");
					if(goReturn==1||goReturn==null){
						location.href="addresslist.html?back="+goReturn;
					}
					else if(goReturn==2){
						location.href="checkout.html"
					}
				}
				else{
					alert(data.message);
					show.close_cover();          //关闭遮罩
				}	
			},
			error : function(e) {
				alert("出现错误 ，请重试");
			}
		}) 
	});

	
	//更换默认
		$(".is_default label").click(function(){
			$(".is_default label").removeClass("selected");
			$(this).addClass("selected");
		})
		
		
		$(".go_back").click(function(){
	var go_back=getUrlParam("back");
	if(go_back==1||go_back==null){
		location.href="addresslist.html?back=1";
	}
	else if(go_back==2){
		location.href="addresslist.html?back=2";
	}
})
});
</script>
<#include 'common/show.html' />
<#include 'common/float_footer.html' />
<#include 'common/footer.html' />